package com.soulkun.smarthome.ui.main.home

import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.GridLayoutManager
import com.soulkun.smarthome.R
import com.soulkun.smarthome.databinding.AppFragmentMainHomeDeviceRecentBinding
import com.soulkun.smarthome.ui.main.home.adapter.AppMainHomeDeviceRecentDataListAdapter
import com.soulkun.smarthome.ui.main.home.viewmodel.AppMainHomeDeviceViewModel
import com.soulkun.smarthome.ui.main.home.viewmodel.AppMainHomeViewModel
import soulkun.library.helper.decoration.GridSpaceItemDecorationHelper
import soulkun.library.mvvm.component.BaseDataBindingFragment

class AppMainHomeDeviceRecentFragment(private val viewModel: AppMainHomeDeviceViewModel) :
    BaseDataBindingFragment<AppFragmentMainHomeDeviceRecentBinding>() {

    private val adapter by lazy {
        AppMainHomeDeviceRecentDataListAdapter(mContext, viewModel.deviceDataRecentList)
    }

    override fun setLayout(): Int {
        return R.layout.app_fragment_main_home_device_recent
    }

    override fun initView() {
        requireDataBinding().rvMainHomeDeviceRecentListData.run {
            layoutManager = GridLayoutManager(mContext, 2)
            adapter = this@AppMainHomeDeviceRecentFragment.adapter
            if (itemDecorationCount == 0) {
                addItemDecoration(GridSpaceItemDecorationHelper(15, 15))
            }
        }
    }

    override fun initData() {
        viewModel.getDeviceRecentData()
    }

    override fun initListener() {
    }

    override fun doOnCreate() {
    }

}